<template>
  <div>
    <!-- 选择文件 -->
    <el-dialog title="添加规范性操作文件" append-to-body :visible.sync="showGFFilesAction" width="50%" :before-close="close">
      <el-form inline model="form" size="small" @keyup.enter.native="refreshList()">
        <el-form-item label="文件名称:" prop="name"><el-input v-model="form.name" clearable class="w160" placeholder="请输入"></el-input></el-form-item>
        <el-form-item label="文件编号:" prop="fileNumber"><el-input v-model="form.fileNumber" clearable class="w160" placeholder="请输入"></el-input></el-form-item>
        <el-form-item>
          <el-button type="primary" @click="refreshList(1)">查询</el-button>
          <el-button type="default" plain @click="resetSearch">重置</el-button>
        </el-form-item>
      </el-form>
      <el-table ref="table" :data="allguifanList" height="460px" header-row-class-name="gray_bg" :row-style="rowStyle" v-loading="loading" @select="handleSelectionChange">
        <el-table-column type="selection" width="30" :selectable="selectable"></el-table-column>
		<el-table-column label="文件编号" prop="fileNumber" :width="getAdaptionWidth('fileNumber', allguifanList)"></el-table-column>
		<el-table-column label="文件版本号" prop="versionNumber" :width="getAdaptionWidth('versionNumber', allguifanList)"></el-table-column>
        <el-table-column label="文件名称" show-overflow-tooltip>
          <template slot-scope="scope">
            <el-tooltip effect="dark" content="文件已加密" placement="top-start" v-if="scope.row.isEncryption == 1">
            	<div class="flex_start">
            		<span class="pointer f14 main_co">{{ scope.row.name }}</span>
            		<el-icon class="iconfont icon-bofangqi-suoping ml10"></el-icon>
            	</div>
            </el-tooltip>
            <span class="pointer f14 main_co" v-else @click="preContent(scope.row,4)">{{ scope.row.name }}</span>
          </template>
        </el-table-column>
        <el-table-column label="操作" fixed="right" width="220">
          <template slot-scope="scope">
            <el-button class="pointer f12" size="mini" @click="pre(scope.row)" v-if="scope.row.isSystemCover == 1">封面预览</el-button>
            <span class="" v-else style="width:100px;height: 28px;display: inline-block;"></span>
            <el-button class="pointer f12" size="mini" v-if="scope.row.isEncryption == 1" @click="applyShow(scope.row,'file')">申请解密</el-button>
          </template>
        </el-table-column>
      </el-table>
      <span slot="footer" class="dialog-footer flex_between">
        <!-- <el-button @click="showJLFilesAction = false">取 消</el-button> -->
        <el-button type="primary" size="mini" @click="onConfirm">确 定</el-button>
        <el-pagination
          @size-change="sizeChangeHandle"
          @current-change="currentChangeHandle"
          :current-page="pageNo"
          :page-size="pageSize"
          :total="total"
          background
          layout="total, prev, pager, next, jumper"
        ></el-pagination>
      </span>
    </el-dialog>
    <pdf :pdfUrl="src" ref="pdf"></pdf>
    <encryption :list="rowFileList" ref="encryption"></encryption>
  </div>
</template>

<script>
import { getguifanList } from '@/api/myapi/tixiwenjian';
import pdf from '../pdf/index.vue';
export default {
  components: {
    pdf
  },
  data() {
    return {
      showGFFilesAction: false,
      allguifanList: [],
      fileList: [],
      pageNo: 1,
      pageSize: 6,
      total: 0,
      form: {},
      src: '',
      applyform: {
        router: '',
        name: ''
      },
      rowStyle: {
        height: '48px'
      }
    };
  },
  created() {
    this.refreshList();
  },
  methods: {
    selectable(row,index){
      console.log(row)
      return row.isEncryption==1?false:true
    },
    pre(item) {
      if (item.templateCover) {
        this.src = item.templateCover;
        this.$refs.pdf.open();
      }
    },
    resetSearch() {
      this.form = {};
	  this.pageNo=1;
	  this.refreshList();
    },
    handleSelectionChange(selection, row) {
      this.fileList = selection;
    },
    onConfirm() {
      if (this.fileList.length == 0) {
        this.$message.error('请选择文件');
        return;
      }
      this.$emit('confirm', { type: 'guifan', file: this.fileList });
	  this.form={};
      this.showGFFilesAction = false;
    },
    open() {
      this.showGFFilesAction = true;
      this.$nextTick(() => {
        this.$refs.table.clearSelection();
      });
    },
	close(done){
		this.form={};
		done();
	},
    // 当前页
    currentChangeHandle(val) {
      this.pageNo = val;
      this.refreshList(val);
    },
    // 获取记录文件
    refreshList(pageNo = 1) {
      this.loading = true;
      getguifanList(
        {
          current: pageNo,
          size: this.pageSize,
          processStatus: 7,
          ...this.form
        },
        'systemguifanfilesprocess'
      ).then(({ data }) => {
        if (data.code == 200) {
          this.allguifanList = data.data.records;
          this.total = data.data.total;
          this.loading = false;
        }
      });
    }
  }
};
</script>

<style></style>
